import time
from pprint import pprint

from selenium import webdriver
from selenium.webdriver.common.by import By

# 打开网址  请求邮箱
driver = webdriver.Chrome()
driver.get('https://mail.qq.com/')
time.sleep(5)
"""
# 登录页frame并切换
login = driver.find_element(By.ID,'login_frame')
driver.switch_to.frame(login)
# 账号输入框并输入
driver.find_element(By.ID,'u').send_keys('619469654@qq.com')
# 密码输入框并输入
driver.find_element(By.ID,'p').send_keys('JH42***46')
# 登录按钮并点击
driver.find_element(By.ID,'login_button').click()
# 获取所有cookie信息

time.sleep(30)
pprint(driver.get_cookies())
"""
cookies = [{'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'ssl_edition',
  'path': '/',
  'secure': False,
  'value': 'sail.qq.com'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'new_mail_num',
  'path': '/',
  'secure': False,
  'value': '619469654&7'},
 {'domain': '.mail.qq.com',
  'expiry': 1655367293,
  'httpOnly': False,
  'name': 'edition',
  'path': '/',
  'secure': False,
  'value': 'mail.qq.com'},
 {'domain': '.mail.qq.com',
  'expiry': 1655367293,
  'httpOnly': False,
  'name': 'qm_logintype',
  'path': '/',
  'secure': False,
  'value': 'qq'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'sid',
  'path': '/',
  'secure': False,
  'value': '619469654&32754f636a63547fefa67e572003c888,qZXFZeGM4czkyUm41aU4zWHBxOVlsdk10V3lXN0s1cm5vRUtCMTVJM0Q4a18.'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'pt4_token',
  'path': '/',
  'secure': False,
  'value': 'MhblqYbdvm5QIcnUjIEeN2BN5i24wY72MxsNl8qjj9M_'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'xm_skey',
  'path': '/',
  'secure': False,
  'value': '13102661644344150&9eb55545d1885310d30936884ad8283b'},
 {'domain': '.mail.qq.com',
  'expiry': 1684311394,
  'httpOnly': False,
  'name': 'webp',
  'path': '/',
  'secure': False,
  'value': '1'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'xm_data_ticket',
  'path': '/',
  'secure': False,
  'value': '13102661644344150&CAESIFBVUkZqETbG7aluMAE1znxL7rnFjnzy86G4IidIBdiT'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'p_skey',
  'path': '/',
  'secure': True,
  'value': 'eqYxc8s92Rn5iN3Xpq9YlvMtWyW7K5rnoEKB15I3D8k_'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'qm_domain',
  'path': '/',
  'secure': False,
  'value': 'https://mail.qq.com'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'xm_sid',
  'path': '/',
  'secure': False,
  'value': 'zVZRX4xbWGgu7HBGACRaOAAA'},
 {'domain': '.mail.qq.com',
  'expiry': 1655367293,
  'httpOnly': False,
  'name': 'qm_device_id',
  'path': '/',
  'secure': False,
  'value': 'Pu0tkXpcDJ7HHtSuCj393AF0Or2hFdAigWDgL+Qxmc3HoERmm8RsmUy0qDirsCjo'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'username',
  'path': '/',
  'secure': False,
  'value': '619469654&619469654'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'qm_username',
  'path': '/',
  'secure': False,
  'value': '619469654'},
 {'domain': '.mail.qq.com',
  'expiry': 1655367393,
  'httpOnly': False,
  'name': 'CCSHOW',
  'path': '/',
  'secure': False,
  'value': '000000'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'xm_muti_sid',
  'path': '/',
  'secure': False,
  'value': '13102661644344150&zVZRX4xbWGgu7HBGACRaOAAA'},
 {'domain': '.qq.com',
  'expiry': 2147483746,
  'httpOnly': False,
  'name': 'RK',
  'path': '/',
  'secure': False,
  'value': 'bH2loAqQQd'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'p_uin',
  'path': '/',
  'secure': False,
  'value': 'o0619469654'},
 {'domain': '.qq.com',
  'httpOnly': False,
  'name': 'skey',
  'path': '/',
  'secure': False,
  'value': '@V6JAOxWt1'},
 {'domain': '.qq.com',
  'httpOnly': False,
  'name': 'uin',
  'path': '/',
  'secure': False,
  'value': 'o619469654'},
 {'domain': '.qq.com',
  'expiry': 2147483746,
  'httpOnly': False,
  'name': 'ptcz',
  'path': '/',
  'secure': False,
  'value': '4ad4c0f21717b16fd0f2836fedca11f9f6d98255337238bc5c8df4baa082d0f2'},
 {'domain': '.mail.qq.com',
  'httpOnly': False,
  'name': 'xm_uin',
  'path': '/',
  'secure': False,
  'value': '13102661644344150'},
 {'domain': '.qq.com',
  'expiry': 1655367391,
  'httpOnly': False,
  'name': 'ptui_loginuin',
  'path': '/',
  'secure': False,
  'value': '619469654@qq.com'}]


driver.delete_all_cookies()
# 添加cookie
for cookie in cookies:
    driver.add_cookie(cookie)

# 刷新
time.sleep(5)
driver.refresh()

# 退出邮箱
time.sleep(2)
driver.quit()